<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!--
        在严格模式下，如果进入执行环境时没有设置 this 的值，this 会保持为 undefined，如下
        function f2(){
            "use strict"; // 这里是严格模式
            return this;
            }

            f2() === undefined; // true
    -->
    <script>
        {
            let a={fun:function(){
                    console.log(this);//object a
                },
               arr: ()=>{
                    console.log(this);//window
                },
                level2:{fun(){
                    console.log(this);//object level2
                },
                }
            }
        // a.fun();
        // a.arr();
        // a.level2.fun();

        }

        {
            //把上级的this保存到self，然后再到内部函数调用
            let b={
                name:"kevin",
                level1(){
                    let self=this;
                    return {level2(){
                        console.log(self);
                    }}
                },
                
            }
          //  b.level1().level2();

        }

        {
            //在普通对象里，无论多深的箭头函数里this都是指向window
            let c={
                name:"kevin",
                basefuns:()=>{
                    console.log(this);
                },
                funs:{funs1:()=>{
                    console.log(this);
                },
            },
                deepfuns:{
                    deepfuns1:{
                        deepfuns2:()=>{
                        console.log(this);
                        }
                    }
                }
           
            
        }
        c.basefuns();
        c.funs.funs1();
        c.deepfuns.deepfuns1.deepfuns2();
        }
    </script>
</head>
<body>
    
</body>
</html>